/*
 * 1. Model생성.
 * 2. 데이터 생성.
 * 3. Store생성.
 *
 * 4. 데이터 접근.
 */

Ext
		.setup({

			tabletStartupScreen : "./tabletStartupScreen.png",
			phoneStartupScreen : "./phoneStartupScreen.png",

			tabletIcon : "./tabletIcon.png",
			phoneIcon : "./phoneIcon.png",
			glossOnIcon : true,
			statusBarStyle : "black",
			fullscreen : true,
			preloadImages : [],
			scope : this,

			onReady : function() {

				// 1. Model생성.
				Ext.regModel('User', 
						{idProperty : 'id',fields : [ 
						{name : 'id'}, {name : 'firstName',type : 'string'}, {name : 'lastName',type : 'string'}, ] } );

				// 2. 데이터 생성.
				var objData = [ {id : "1",firstName : "data1-1",lastName : "data1-2"}, 
				                {id : "2",firstName : "data2-1",lastName : "data2-2"}, 
				                {id : "3",firstName : "data3-1",lastName : "data3-2"}, 
				                {id : "4",firstName : "data4-1",lastName : "data4-2"}, 
				                {id : "5",firstName : "data5-1",lastName : "data5-2"}, 
				                {id : "6",firstName : "data6-1",lastName : "data6-2"} ];

				var objStoreListener = {
					add : function() {
						console.log("add");
					},
					beforeload : function() {
						console.log("beforeload");
					},
					datachanged : function() {
						console.log("datachanged");
					},
					exception : function() {
						console.log("exception");
					},
					load : function() {
						console.log("load");
					},

					remove : function() {
						console.log("remove___");
					},
					update : function() {
						console.log("loadexception");
					}
				}

				// 3. Store생성.
				var dataStore = new Ext.data.Store({
					autoLoad : true,
					model : 'User',
					data : objData,
					listeners : objStoreListener
				});

				// 4. 데이터 접근.
				loadData();
				function loadData() {
					// 데이터 읽기.
					var record = dataStore.getAt(1);
					console.log(record);
					console.log(record.data.id);
					console.log(record.data.firstName);
					console.log(record.data["lastName"]);
				}

				new Ext.List(
						{
							fullscreen : true,
							store : dataStore,
							itemTpl : '<div class="contact2"><strong>{firstName}</strong> {lastName}</div>'
						});
			}
		});